<template>
    <div class="doc-content-wrapper">
        <div class="doc-content-container">
            <div class="doc-content">
                <h2 class="mb-5 flex items-center">修改数组对象的属性名</h2>
                <Codemirror :code="code1" name="for修改数组对象的属性名" class="mb-10" />
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

export default defineComponent({
    setup () {
        const code1 = ref(`var arr =  [{id:1,name:'张三'},{id:2,name:'李四'}]
        
for(var i in arr){
    for(var j in arr[i]){
        if(j == 'name'){
        arr[i]['text'] = arr[i][j]  //修改属性名为“text”
        delete arr[i]['name']  //删除“name”
        }
    }
}

console.log(JSON.stringify(arr))`)

        return {
            code1
        }
    }
})
</script>

<style scoped>

</style>